package com.baizhi.service.impl;

import com.baizhi.dao.StudentDao;
import com.baizhi.entity.Student;
import com.baizhi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Student> findAll() {
        return studentDao.findAll();
    }

    // 查询全部
    @Override
    public List<Student> findAll(String searchCol, String searchValue) {
        return studentDao.find(searchCol,searchValue);
    }

    // 分页查询
    @Override
    public List<Student> findAll(Integer pageNow, Integer rows, String searchCol, String searchValue) {
        int start = (pageNow - 1)*rows;
        // findByLikePage：既做模糊又做分页
        return studentDao.findByLikePage(start,rows,searchCol,searchValue);
    }

    // 查询总数
    @Override
    public Integer totalCounts(String searchCol, String searchValue) {
        return studentDao.totalCounts(searchCol, searchValue);
    }
}
